using ObjFileLoader.Common;
using ObjFileLoader.Data.DataStore;
using ObjFileLoader.Data.VertexData;
using ObjFileLoader.TypeParsers.Interfaces;
using System;

namespace ObjFileLoader.TypeParsers
{
	public class VertexParser : TypeParserBase, IVertexParser, ITypeParser
	{
		private readonly IVertexDataStore _vertexDataStore;

		protected override string Keyword => "v";

		public VertexParser(IVertexDataStore vertexDataStore)
		{
			_vertexDataStore = vertexDataStore;
		}

		public override void Parse(string line)
		{
			string[] array = line.Split(new char[1]
			{
				' '
			}, StringSplitOptions.RemoveEmptyEntries);
			float x = array[0].ParseInvariantFloat();
			float y = array[1].ParseInvariantFloat();
			float z = array[2].ParseInvariantFloat();
			Vertex vertex = new Vertex(x, y, z);
			_vertexDataStore.AddVertex(vertex);
		}
	}
}
